<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>setHandle</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">setHandle</h1>
<h2>Purpose</h2>
<p>Assign function handle to existing Function object</p>
<h2>Syntax</h2>
<pre class="synopsis">setHandle(F,@fun)</pre>
<pre class="synopsis">F.setHandle(@fun)</pre>
<h2>Description</h2>
<p></p>
        Overwrites function handle of the <tt>Function</tt> object with a new one. This method is suitable
        for specification of functions where the parameters are stored under <tt>Data</tt> property. Look at
        examples for better explanation.
	<h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>F</tt></td>
<td>
<p></p>Existing <tt>Function</tt> object which function we want to overwrite.
        <p>
	    		Class: <tt>Function</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>F</tt></td>
<td>
<p></p>Representation of the new function given as <tt>function_handle</tt> class.
        <p>
	    		Class: <tt>function_handle</tt></p>
</td>
</tr>
</tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>F</tt></td>
<td>
<p></p>Modified <tt>Function</tt> objects.<p>
	    		Class: <tt>Function</tt></p>
</td>
</tr></tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3> Construct anonymous function <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle1.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle1.png"> where <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle2.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle2.png"> is a parameter. 
            Assume that the value of <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle3.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle3.png"> is not going to change in the future. 
        It suffices to declare the value of <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle4.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle4.png"> before constructing the object, i.e. <pre class="programlisting"> k=2; </pre>
<pre class="programlisting"></pre> Then we can construct the object with this value of the parameter as <pre class="programlisting"> F1 = Function(@(x) k*x) </pre>
<pre class="programlisting">Function: @(x)k*x
</pre> Evaluating this function will always take <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle5.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle5.png"> value, e.g in this case we get 2 <pre class="programlisting"> feval(F1.Handle,1) </pre>
<pre class="programlisting">
ans =

     2

</pre> Changing the value of <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle6.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle6.png"> does not affect the function <pre class="programlisting"> k=3; </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> feval(F1.Handle,1) </pre>
<pre class="programlisting">
ans =

     2

</pre> If the value of <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle7.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle7.png"> may change in the future, one option is to make function depedent on two
        variables <pre class="programlisting"> F2 = Function(@(k,x) k*x) </pre>
<pre class="programlisting">Function: @(k,x)k*x
</pre> Evaluation of this function requires two arguments, i.e. <pre class="programlisting"> feval(F2.Handle,2,1) </pre>
<pre class="programlisting">
ans =

     2

</pre> Another option is to store the parameter <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle8.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle8.png"> inside the <tt>Data</tt> property.  Let's create empty function with the initial value <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle9.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle9.png"> 
      <pre class="programlisting"> F3 = Function([],struct('k',2)) </pre>
<pre class="programlisting">Empty Function
</pre> Now we can assign the function handle with the reference to the parameter <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle10.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle10.png"> 
            stored inside <tt>F3</tt> object, i.e. <pre class="programlisting"> F3.setHandle(@(x) F3.Data.k*x) </pre>
<pre class="programlisting">Function: @(x)F3.Data.k*x
</pre> If we change the value of the parameter <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle11.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle11.png"> inside the object<pre class="programlisting"> F3.Data.k = 3; </pre>
<pre class="programlisting"></pre> this new value will be taken for evaluation.<pre class="programlisting"> feval(F3.Handle,1) </pre>
<pre class="programlisting">
ans =

     3

</pre>
<h3>Example 
				2</h3> Construct anonymous function <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle12.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle12.png"> with parameters <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle13.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle13.png"> and <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle14.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle14.png">. Firstly, construct empty <tt>Function</tt> object and store the parameters in the <tt>Data</tt> property.<pre class="programlisting"> F = Function([], struct('a',10.4,'b',-0.56)) </pre>
<pre class="programlisting">Empty Function
</pre> Secondly, set the handle pointing to the parameters stored inside <tt>Data</tt> property <pre class="programlisting"> F.setHandle(@(x)F.Data.a*sin(F.Data.b*x)) </pre>
<pre class="programlisting">Function: @(x)F.Data.a*sin(F.Data.b*x)
</pre> The values of the parameters <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle15.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle15.png">, <img src="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle16.png" alt="../../../../../../fig/mpt/modules/geometry/functions/@Function/sethandle16.png"> can be modified after construction of the object.
        The <tt>Function</tt> object will then take the new values of the parameters. <pre class="programlisting"> F.Data.a = 12.78; F.Data.b = -0.93 </pre>
<pre class="programlisting">Function: @(x)F.Data.a*sin(F.Data.b*x)
</pre>
<h3>Example 
				3</h3> For functions arrays you must correctly refer to the appropriate index of the function data  Allocate an array of <tt>Function</tt> objects <pre class="programlisting"> F(2,1) = Function </pre>
<pre class="programlisting">Array of 2 Functions.
</pre> Assign the data <pre class="programlisting"> F(1).Data = struct('a',-1,'b',2); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> F(1).setHandle(@(x)F(1).Data.a*sin(F(1).Data.b*x)); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> F(2).Data = struct('a',-3,'b',4); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> F(2).setHandle(@(x)F(2).Data.a*sin(F(2).Data.b*x)); </pre>
<pre class="programlisting"></pre>
<h3>Example 
				4</h3> Assignment of multiple function handles is possible as well. Allocate the array of 2 <tt>Function</tt> objects.<pre class="programlisting"> F(2) = Function </pre>
<pre class="programlisting">Array of 2 Functions.
</pre> Assign two function handles must be done in a cell<pre class="programlisting"> F.setHandle({@(x)x, @(x)x^2}) </pre>
<pre class="programlisting">Array of 2 Functions.
</pre>
<h2>See Also</h2>
<a href="../@AffFunction/afffunction.html">afffunction</a>, <a href="../@QuadFunction/quadfunction.html">quadfunction</a>, <a href="./sethandle.html">sethandle</a><p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="../../../../../mpt.html" class="button">&#9664;</a>  </td>
<td align="left">mpt</td>
<td>  </td>
<td align="right">isemptyfunction</td>
<td align="right" width="20"><a href="isemptyfunction.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2010-2013</b>     Martin Herceg: ETH Zurich,    <a href="mailto:herceg@control.ee.ethz.ch">herceg@control.ee.ethz.ch</a></p>
</body>
</html>
